# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=qcoro
pkgver=0.11.0
pkgrel=0
pkgdesc="C++ Coroutines for Qt"
url="https://qcoro.dvratil.cz"
arch="all"
license="MIT"
depends_dev="
	qt5-qtbase-dev
	qt5-qtwebsockets-dev
	qt5-qtdeclarative-dev
	qt6-qtbase-dev
	qt6-qtwebsockets-dev
	"
makedepends="$depends_dev
	cmake
	samurai
	"
checkdepends="
	dbus-x11
	xvfb-run
	"
subpackages="$pkgname-dev $pkgname-qt6"
source="https://github.com/danvratil/qcoro/archive/v$pkgver/qcoro-v$pkgver.tar.gz"

build() {
	cmake -B build-qt5 -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=TRUE \
		-DUSE_QT_VERSION=5 \
		-DQCORO_BUILD_EXAMPLES=OFF
	cmake --build build-qt5

	cmake -B build-qt6 -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=TRUE \
		-DUSE_QT_VERSION=6 \
		-DQCORO_BUILD_EXAMPLES=OFF
	cmake --build build-qt6
}

check() {
	cd build-qt5
	CTEST_OUTPUT_ON_FAILURE=TRUE xvfb-run ctest

	cd "$builddir"/build-qt6

	# test-qcorolocalsocket fails
	CTEST_OUTPUT_ON_FAILURE=TRUE xvfb-run ctest -E "test-qcorolocalsocket"
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt5
	DESTDIR="$pkgdir" cmake --install build-qt6
}

qt6() {
	cd "$builddir"

	amove usr/lib/libQCoro6*
}

sha512sums="
bde5c5cd9f3c038e6b5ec5a6adae5ae2218edd9df350e75fc5d8db31d9339484e92cc88fdc37fa0539e0cdf1f53731418ebfa73b94564e993d7b02168988771b  qcoro-v0.11.0.tar.gz
"
